# -*- coding: utf-8 -*-
# @Author: Tim Liu
# @Date: 2024-07-11
# @Last Modified by: Tim Liu
# @Last Modified time: 2024-07-11
import logging
# @Description: Image Document Loader for RAG

from typing import Iterator

from langchain_core.document_loaders import BaseLoader
from langchain_core.documents import Document
from langchain_core.messages import HumanMessage
from config.settings import *
from crewplus.services.chat_openai_service import ChatOpenAIService
from crewplus.services.docintel_service import DocintelService
from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader



class ExcelDocumentLoader(BaseLoader):
    """An image document loader that loads an image file into Document."""

    def __init__(self, file_path: str) -> None:
        """Initialize the loader with a file path.

        Args:
            file_path: The path to the file to load.
        """
        self.file_path = file_path

    def lazy_load(self) -> Iterator[Document]:  # <-- Does not take any arguments
        """A lazy loader that reads a file line by line.

        When you're implementing lazy load methods, you should use a generator
        to yield documents one by one.
        """

        loader = AzureAIDocumentIntelligenceLoader(
            # =endpoint, api_key=key, file_path=file_path, api_model="prebuilt-layout"
            api_endpoint=DOCINTEL_AZURE_OPENAI_ENDPOINT, api_key=DOCINTEL_AZURE_OPENAI_API_KEY,  file_path=self.file_path, api_model="prebuilt-layout"
        )

        documents = loader.load()
        logging.info("documents:%s",documents)
        return documents